const { login, isAccess, register, getLessors } = require('../dao/lessorsDao');


module.exports = {
    // 获取出租方信息
    getLessors: async (lessorsId) => {
        console.log('成功进入第二层获取出租方信息')
        return await getLessors(lessorsId)
    },
    //验证注册用户名是否重复
    isAccess: async function (account) {
        const data = await isAccess(account);
        if (data.length > 0) {
            return {
                message: '账号已存在',
                status: 0
            }
        }
        return {
            message: '账号合法',
            status: 1
        }
    },

    //点击注册
    register: async account => {
        const data = await register(account);
        if (data._id) {
            return {
                message: '注册成功',
                status: 1
            }
        }
        return {
            message: '注册失败',
            status: 0
        }
    },
    //登陆
    login: async function (lessors) {
        // 调用第三层 usersDao.js中暴露的 login 方法
        const data = await login(lessors);
        if (data.length > 0) {
            return {
                message: '登录成功',
                status: 1,
                data
            }
        } else {
            return {
                message: '登录失败',
                status: 0,
            }
        }
    }



}
